<?php

class AppPermissions extends Object
{

	var $groups=array("Public","User","Admin");
		
		var $Clientes=array(
		'index'=>'User',
		'view'=>'User',
		'add'=>'Public',
		'edit'=>'User',
		'delete'=>'Admin');
		
		var $Productos=array(
		'index'=>'User',
		'view'=>'User',
		'add'=>'Admin',
		'edit'=>'Admin',
		'delete'=>'Admin');
		
		var $Menus=array(
		'index'=>'Public',
		'view'=>'Public',
		'add'=>'Admin',
		'edit'=>'Admin',
		'delete'=>'Admin');
		
		function __currentActionGroup($controller_name,$action)
		{
			if(!isset($this->{$controller_name})) return false;
			if(!isset($this->{$controller_name}[$action])) return false;
			
			return $this->{$controller_name}[$action];
		}
		
		function groupHasAccess($controller, $action, $group="Public")
		{
			$group_index=array_search($group,$this->groups);
			$allowedGroup=$this->__currentActionGroup($controller,$action);
			$allowedGroup_index=array_search($allowedGroup,$this->groups);
			
			return $group_index>=$allowedGroup_index;
		}
}	
?>